package com.cwj;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author: Chenwujie
 * @date: 2021-06-11 13:21
 */
public class HashMapTest {
    public static void main(String[] args) throws InterruptedException {
        Map<Object, Object> map = new HashMap<>();
        ExecutorService executorService = Executors.newCachedThreadPool();
        for (int i = 0; i < 100; i++) {
            executorService.execute(new MyTask(map));
        }

        Thread.sleep(10000);
        executorService.shutdown();
    }

    public static class MyTask implements Runnable{
        private Map<Object, Object> map;
        private Random random = new Random();
        public MyTask(Map<Object, Object> map) {
            this.map = map;
        }

        @Override
        public void run() {
            map.put(random.nextDouble(), 1);
        }
    }
}
